package com.wiscamp.ninechapters.tags.infrastructure.mappers;

import com.wiscamp.ninechapters.tags.infrastructure.po.SubjectView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;

/**
 * 学科仓储对象
 *
 * @author yifeng
 */
@Repository
public interface SubjectViewMapper extends JpaRepository<SubjectView, Long>, JpaSpecificationExecutor<SubjectView> {
    /**
     * 通过代码获取学科
     *
     * @param subjectCode
     * @return
     */
    @Query(value = "select s from SubjectView s where s.subjectCode = :subjectCode")
    SubjectView findBySubjectCode(String subjectCode);

    /**
     * 通过名称获取学科列表
     *
     * @param subjectName
     * @return
     */
    @Query(value = "select s from SubjectView s where s.subjectName = :subjectName")
    Collection<SubjectView> findListBySubjectName(String subjectName);

    /**
     * 获取所有未删除学科
     *
     * @return
     */
    @Query(value = "select s from SubjectView s where s.enabled")
    Collection<SubjectView> findListByAvailable();

    /**
     * 分页获取学科列表
     *
     * @param spec
     * @param pageable
     * @return
     */
    Page<SubjectView> findAll(Specification<SubjectView> spec, Pageable pageable);
}